package main

import "fmt"

type student struct {
	id int
	name string
	sex byte
	age int
	addr string
}

func aaaa(a student)  {
	a.id = 666
	fmt.Println("aaaa s10", a)
}

func bbbb(a *student)  {
	a.id = 666
	fmt.Println("bbbb s10", a)
}

func main()  {
	//赋值，这里要注意，如果只写值的话，要给结构体的全部元素赋值，不能有缺省的，否则会编译不过
	var s1 = student{1, "go", 'm', 22, "上海"}
	fmt.Println(s1)

	//部分初始化
	s2 := student{id:1, age:22, sex:'g'}
	fmt.Println(s2)

	//指针
	var s3 *student = &student{11, "c++", 'g', 22, "北京"}
	fmt.Println(s3)

	//自动推导类型
	s4 := student{23, "php", 'm', 23, "天津"}
	fmt.Println(s4)

	//结构体成员的使用
	var s5 student
	s5.id = 11
	s5.name = "Java"
	s5.sex = 'm'
	s5.age = 20
	s5.addr = "上海"
	fmt.Println(s5)

	//指针结构体成员操作
	var s6 student
	var p1 *student
	p1 = &s6
	p1.id = 12
	p1.name = "Js"
	p1.sex = 'm'
	p1.age = 20
	p1.addr = "上海"
	fmt.Println(p1)

	//第二种方式通过new函数
	p2 := new(student)
	p2.id = 12
	p2.name = "Css"
	p2.sex = 'm'
	p2.age = 20
	p2.addr = "上海"
	fmt.Println(p2)

	//大小比较和赋值
	s7 := student{11, "test", 'm', 19, "北京"}
	s8 := student{11, "test", 'm', 19, "北京"}
	s9 := student{13, "test", 'm', 19, "北京"}
	fmt.Println("s7 == s8", s7 == s8)
	fmt.Println("s8 == s9", s8 == s9)

	var s10 student
	s10 = s9
	fmt.Println("s10 =", s10)


	//函数值传递,函数的里的操作不会影响外边
	aaaa(s10)
	fmt.Println("aaaa", s10)

	//函数地址传递，函数里的操作会影响到外边
	bbbb(&s10)
	fmt.Println("bbbb", s10)
}
